package gamesound;

import org.newdawn.slick.*;

public class Zvuk {
	
	private final static int brPesama = 5;
	
	private static Zvuk instance = null;
	private static float pitch = 1;
	private static float volume1 = 0.4f;
	private static float volume2 = 0.7f;
	
	private Sound pucanj;
	private Sound eksplozija;
	private Sound bossPuca;
	private Music[] pozadina;
	private int tek;
	private boolean music;
	private boolean soundfx;
	
	private Zvuk () {
		tek = 4;
		music = true;
		soundfx = true;
		try {
			pucanj = new Sound ("res/pucanj.wav");
			eksplozija = new Sound ("res/battle002.wav");
			setBossPuca(new Sound ("res/boss.wav"));
			pozadina = new Music[brPesama];
			pozadina[0] = new Music ("res/ACDC_Thunderstruck_8_bit.wav");
			pozadina[1] = new Music ("res/Black_Sabbath_Paranoid_8_bit.wav");
			pozadina[2] = new Music ("res/Dropkick_Murphys_Im_Shipping_up_to_Boston_8_bit.wav");
			pozadina[3] = new Music ("res/Europe_The_final_countdown_8_bit.wav");
			pozadina[4] = new Music ("res/Iron_Maiden_The_Trooper_8_bit.wav");
		} catch (SlickException e) {}
	}
	
	public synchronized static Zvuk dohvZvuk() {
		if(instance == null) {
			instance = new Zvuk();
		}
		return instance;
	}

	public Sound getPucanj() {
		return pucanj;
	}

	public void setPucanj(Sound pucanj) {
		this.pucanj = pucanj;
	}

	public Sound getEksplozija() {
		return eksplozija;
	}

	public void setEksplozija(Sound eksplozija) {
		this.eksplozija = eksplozija;
	}
	
	public Sound getBossPuca() {
		return bossPuca;
	}

	public void setBossPuca(Sound bossPuca) {
		this.bossPuca = bossPuca;
	}

	public Music[] getPozadina() {
		return pozadina;
	}

	public void setPozadina(Music[] pozadina) {
		this.pozadina = pozadina;
	}

	public int getTek() {
		return tek;
	}

	public void setTek(int tek) {
		this.tek = tek;
	}

	public boolean isMusic() {
		return music;
	}

	public void setMusic(boolean music) {
		this.music = music;
	}

	public boolean isSoundfx() {
		return soundfx;
	}

	public void setSoundfx(boolean soundfx) {
		this.soundfx = soundfx;
	}

	public void eksplodiraj () {
		if (soundfx) {
			eksplozija.play(pitch, volume2);
		}
	}
	
	public void pucaj () {
		if (soundfx) {
			pucanj.play(pitch, volume2);
		}
	}
	
	public void boss () {
		if (soundfx) {
			bossPuca.play(pitch, volume2);
		}
	}
	
	public Music dohvTekucu () {
		return pozadina[tek];
	}
	
	public void pustiMuziku () {
		int br;
		if (music && !pozadina[tek].playing()) {
			do {
				br = (int)(Math.random()*5);
				if (br > 4) br = 4;
			} while (tek == br);
			pozadina[br].play(pitch, volume1);
			tek = br;
		}
		if (!music) {
			pozadina[tek].stop();
		}
	}
	
	public void proba () {
	}

}
